package com.ruoyi.demo.controller;

import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.demo.service.IMesBindTaskDataService;
import com.ruoyi.demo.service.IProTaskSnDataService;
import com.ruoyi.demo.service.JiandaoyunService;
import com.ruoyi.demo.vo.SnWareHouseDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Slf4j
@RequestMapping("/api/jiandaoyun")
public class JdyController {

    @Resource
    private JiandaoyunService jiandaoyunService;
    @Autowired
    private IMesBindTaskDataService mesBindTaskDataService;
    /**
     * 批量发送仓库数据到简道云
     */
    @PostMapping("/batch-send")
    public AjaxResult batchSendToJdy() {
        List<SnWareHouseDataVo> dataList=mesBindTaskDataService.selectSnWareHouseList();
        if (dataList.isEmpty()) {
            return AjaxResult.error("数据列表不能为空");
        }
        List<String> needSendSnList = dataList.stream().map(SnWareHouseDataVo::getSn).collect(Collectors.toList());
        log.info("需要发送简道云的SN List：{}", JSONUtil.toJsonStr(dataList));
        String response = jiandaoyunService.batchSendToJdy(dataList);
        return AjaxResult.success("发送成功", response);
    }
}